package org.toycode.logindemo.application.tapestry.util;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.services.Response;

final public class JSONStreamResponse implements StreamResponse {

    private String source;

    public JSONStreamResponse(final String source) {
        this.source = source;
    }

    public String getContentType() {
        return "application/json";
    }

    public InputStream getStream() throws IOException {
        final ByteArrayInputStream stream =
                new ByteArrayInputStream(source.getBytes("UTF-8"));
        
        return stream;
    }

    public void prepareResponse(Response response) {
    }
}
